package cn.alm.springmvc01helloworld.controller;

import cn.alm.springmvc01helloworld.entity.Person;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("rtc")
public class RequestTestController {

    @GetMapping("handle01")
    public String handle01(String username, String password, Integer age, Boolean agree) {
        System.out.println("username = " + username);
        System.out.println("password = " + password);
        System.out.println("age = " + age);
        System.out.println("agree = " + agree);
        return "ok";
    }

    @GetMapping("handle02")
    public String handle02(
            @RequestParam("username") String name,
            @RequestParam("password") String pwd,
            @RequestParam("age") Integer age,
            @RequestParam("agree") Boolean agree) {
        System.out.println("name = " + name);
        System.out.println("pwd = " + pwd);
        System.out.println("age = " + age);
        System.out.println("agree = " + agree);
        return "ok";
    }

    @PostMapping("handle03")
    public String handle03(@RequestBody Person person) {
        System.out.println("person.username: " + person.getUsername());
        System.out.println("person.password: " + person.getPassword());
        System.out.println("person.age: " + person.getAge());
        return "ok";
    }

    @PostMapping("handle04")
    public String handle04(@RequestHeader("Origin") String origin) {
        System.out.println("origin = " + origin);
        return "ok";
    }

    @PostMapping("handle05")
    public String handle05(@CookieValue String myCookie) {
        System.out.println("myCookie = " + myCookie);
        return "ok";
    }

    @PostMapping("handle06")
    public String handle06(@RequestBody Person person) {
        System.out.println("person.username = " + person.getUsername());
        System.out.println("person.password = " + person.getPassword());
        System.out.println("person.age = " + person.getAge());
        return "ok";
    }

}
